import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(service=Service('D:\\myproject\\feng-huang\\1.自动化\\1.selenium\\chromedriver.exe'))
driver.maximize_window()
driver.get('https://www.foodtalks.cn/company/Yili/')
time.sleep(2)
dict = {}
driver.find_element(By.CLASS_NAME, 'tab-item').click()
time.sleep(2)

# 简介
unfold_more = driver.find_element(By.XPATH, '//span[text()="展开"]').click()
introduction = driver.find_element(By.XPATH, '//span[text()="公司介绍"]')
if introduction.text == '公司介绍':
    try:
        introduction1 = introduction.find_element(By.XPATH , '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[1]/div[1]/div[2]/div[1]').text
    except:
        introduction1 = ''
    dict['公司介绍'] = introduction1
# 品牌
try:
    brand = driver.find_element(By.XPATH, '//span[text()="品牌"]')
    if brand.text == '品牌':
        brand.click()
        time.sleep(1)
        list_brand = []
        try:
            brands1 = driver.find_elements(By.CLASS_NAME,'el-row')
            for brand11 in brands1:
                list_brand.append(brand11.text)
        except:
            list_brand = ''
        dict['品牌'] = list_brand
except:
    dict['品牌'] = ''
# 产品
try:
    product2 = driver.find_element(By.XPATH, '//span[text()="产品"]')
    if product2.text == '产品':
        product2.click()
        time.sleep(1)
        list_prod = []
        try:
            prods1 = driver.find_elements(By.CLASS_NAME,'el-row')
            for prod11 in prods1:
                list_prod.append(prod11.text)
        except:
            list_prod = ''
        dict['产品'] = list_prod
except:
    dict['产品'] = ''
# 客户
try:
    customer = driver.find_element(By.XPATH, '//span[text()="客户"]')
    if customer.text == '客户':
        customer.click()
        time.sleep(1)
        list_cust = []
        try:
            custs1 = driver.find_elements(By.CLASS_NAME,'customer-list.not-login')
            for cust11 in custs1:
                list_cust.append(cust11.text)
        except:
            list_cust = ''
        dict['客户'] = list_cust
except:
    dict['客户'] = ''
# 供应商
try:
    supplier = driver.find_element(By.XPATH, '//span[text()="供应商"]')
    if supplier.text == '供应商':
        supplier.click()
        time.sleep(1)
        list_supp = []
        try:
            supp1 = driver.find_elements(By.CLASS_NAME,'customer-list.not-login')
            for supp11 in supp1:
                list_supp.append(supp11.text)
        except:
            list_supp = ''
        dict['供应商'] = list_supp
except:
    dict['供应商'] = ''
# 联系方式
try:
    contact = driver.find_element(By.XPATH, '//span[text()="联系方式"]')
    if contact.text == '联系方式':
        contact.click()
        time.sleep(1)
        try:
            contact1 = driver.find_element(By.ID, 'section-content').text
        except:
            contact1 = ''
        dict['联系方式'] = contact1
except:
    dict['联系方式'] = ''

print(dict)
